package nc.hw;

import java.util.Arrays;
import java.util.Scanner;

public class Hj18 {

    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
        int[] nums = new int[7];
        String str = "225.240.129.203~255.110.255.255\n" +
                "183.181.49.4~255.0.0.0\n" +
                "172.177.113.45~255.0.0.0\n" +
                "176.134.46.246~255.0.0.0\n" +
                "153.63.21.56~255.255.58.255\n" +
                "23.135.167.228~255.0.0.0\n" +
                "204.58.47.149~255.0.0.0\n" +
                "113.33.181.46~255.255.255.0\n" +
                "73.245.52.119~255.255.154.0\n" +
                "23.214.47.71~255.0.0.0\n" +
                "139.124.188.91~255.255.255.100\n" +
                "142.94.192.197~255.0.0.0\n" +
                "53.173.252.202~255.0.0.0\n" +
                "127.201.56.50~255.255.111.255\n" +
                "118.251.84.111~255.0.0.0\n" +
                "130.27.73.170~255.0.0.0\n" +
                "253.237.54.56~255.86.0.0\n" +
                "64.189.222.111~255.255.255.139\n" +
                "148.77.44.147~255.0.0.0\n" +
                "59.213.5.253~255.255.0.0\n" +
                "3.52.119.131~255.255.0.0\n" +
                "213.208.164.145~255.255.0.0\n" +
                "24.22.21.206~255.255.90.255\n" +
                "89.43.34.31~255.0.0.0\n" +
                "9.64.214.75~255.0.0.0\n" +
                "110.156.20.173~255.153.0.0\n" +
                "71.183.242.53~255.255.0.0\n" +
                "119.152.129.100~255.0.0.0\n" +
                "38.187.119.201~255.0.0.0\n" +
                "73.81.221.180~255.255.255.255\n" +
                "73.198.13.199~255.0.15.0\n" +
                "99.42.142.145~255.255.255.0\n" +
                "196.121.115.160~255.0.0.0\n" +
                "226.30.29.206~255.0.0.0\n" +
                "244.248.31.171~255.255.255.255\n" +
                "59.116.159.246~255.0.0.0\n" +
                "121.124.37.157~255.0.0.226\n" +
                "103.42.94.71~255.255.0.0\n" +
                "125.88.217.249~255.255.74.255\n" +
                "73.44.250.101~255.255.255.0";
//        while (in.hasNextLine()) {
//            String nextLine = in.nextLine();
//            checkIps(nextLine, nums);
//        }
        for (String s : str.split("\n")) {
            checkIps(s, nums);
            System.out.println(Arrays.toString(nums));
        }
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }

    private static void checkIps(String ipAndCover, int[] nums) {
        String ip = ipAndCover.split("~")[0];
        String cover = ipAndCover.split("~")[1];
        if (localIp(ip)) {
            return;
        }
        boolean errIp = errIp(ip);
        boolean errCover = errCover(cover);
        if (errIp || errCover) {
            nums[5] += 1;
            return;
        }
        if (priIp(ip)) {
            nums[6] += 1;
        }
        nums[getTypeIp(ip)] ++;
    }

    private static boolean localIp(String ip) {
        return ip.startsWith("127") || ip.startsWith("0");
    }

    private static int getTypeIp(String ip) {
        int[] nums = new int[]{1, 128, 192, 224, 240};
        int[] endNums = new int[]{126, 191, 223, 239, 255};
        int i = Integer.parseInt(ip.split("\\.")[0]);
        for (int j = 0; j < 5; j++) {
            if (nums[j] <= i && endNums[j] >= i) {
                return j;
            }
        }
        return 0;
    }

    private static boolean priIp(String ip) {
        if (ip.startsWith("10.") || ip.startsWith("192.168")) {
            return true;
        }
        if (ip.startsWith("172")) {
            String checkNum = ip.split("\\.")[1];
            int i = Integer.parseInt(checkNum);
            return i >= 16 && i <= 31;
        }
        return false;
    }

    private static boolean errCover(String cover) {
        if (errIp(cover)) {
            return true;
        }
        if ("255.255.255.255".equals(cover) || "0.0.0.0".equals(cover)) {
            return true;
        }
        String[] split = cover.split("\\.");
        boolean hadZero = false;
        for (String s : split) {
            int i = Integer.parseInt(s);
            if (hadZero && i != 0) {
                return true;
            }
            if (i != 255) {
                hadZero = true;
            }
            // 从0到255判断
            int start = 0;
            for (int j = 128; j != 0; j /= 2) {
                if (start == i) {
                    break;
                }
                if (start > i) {
                    return true;
                }
                start += j;
            }
        }
        return false;
    }

    private static boolean errIp(String ip) {
        String[] split = ip.split("\\.");
        if (split.length != 4) {
            return true;
        }
        for (String s : split) {
            if (!s.matches("\\d{1,3}")) {
                return true;
            }
            int i = Integer.parseInt(s);
            if (i > 255) {
                return true;
            }
        }
        return false;
    }
}
